package day12.dat12;



import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author success
 * @version 1.0
 * @description:本类用来演示:
 * @date 2019/7/30 0030
 */
public class CollectionsSortDemo {
    public static void main(String[] args) {
        Book b1 = new Book(1,"a西a游记","吴承恩",100.0);
        Book b2 = new Book(2,"c水浒传","施耐庵",150.0);
        Book b3 = new Book(3,"d红a楼梦","曹雪芹",80.0);
        Book b4 = new Book(4,"b三国演义","罗贯中",70.0);
        Book b5 = new Book(5,"f等a一个人的咖啡","九把刀",120.0);
        Book b6 = new Book(6,"n毛泽东讲义","毛润之",120.0);

        List<Book> list = new ArrayList<>();

        list.add(b1);
        list.add(b2);
        list.add(b3);
        list.add(b4);
        list.add(b5);
        list.add(b6);

//        Comparator<Book> c = new Comparator<Book>() {
//            @Override
//            public int compare(Book o1, Book o2) {
//                if(o1.getPrice()>o2.getPrice())
//                    return -1;
//                else if(o1.getPrice()<o2.getPrice())
//                    return 1;
//                return 0;
//            }
//        };

       // Comparator<Book> c = ComparatorFactory.getInstance(ComparatorFactory.NAME);

        Comparator<Book> c = ComparatorFactory.getInstance(ComparatorFactory.PRICE);

       Collections.sort(list, c);

        list.forEach(System.out::println);
    }
}
